package com.duolebo.uteped_sdk.model;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.database.Cursor;

import com.yc.nadalsdk.bean.SleepData;

import java.util.ArrayList;

/**
 * @Author: LiuYang
 * @Date: 2023/12/20 11:57
 * @Description:
 */
public class SleepModel extends BaseModel {

    private String calendarTime;
    private String calendar;
    private int time;
    private int startTime;
    private int endTime;
    private int sleepTime;
    private int sleepType;
    private boolean isSnooze;

    public String getCalendarTime() {
        return calendarTime;
    }

    public void setCalendarTime(String calendarTime) {
        this.calendarTime = calendarTime;
    }

    public String getCalendar() {
        return calendar;
    }

    public void setCalendar(String calendar) {
        this.calendar = calendar;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getStartTime() {
        return startTime;
    }

    public void setStartTime(int startTime) {
        this.startTime = startTime;
    }

    public int getEndTime() {
        return endTime;
    }

    public void setEndTime(int endTime) {
        this.endTime = endTime;
    }

    public int getSleepTime() {
        return sleepTime;
    }

    public void setSleepTime(int sleepTime) {
        this.sleepTime = sleepTime;
    }

    public int getSleepType() {
        return sleepType;
    }

    public void setSleepType(int sleepType) {
        this.sleepType = sleepType;
    }

    public boolean isSnooze() {
        return isSnooze;
    }

    public void setSnooze(boolean snooze) {
        isSnooze = snooze;
    }

    public SleepModel(SleepData sleepData) {
        this.calendar = sleepData.getCalendar();
        this.calendarTime = sleepData.getCalendarTime();
        this.time = sleepData.getTime();
        this.startTime = sleepData.getStartTime();
        this.endTime = sleepData.getEndTime();
        this.sleepTime = sleepData.getSleepTime();
        this.sleepType = sleepData.getSleepType();
        this.isSnooze = sleepData.isSnooze();
    }

    public SleepModel(){}

    /**
     * BaseModel
     *
     * @param model model
     */
    SleepModel(BaseModel model) {
        super(model);
    }

    @Override
    public void writeFieldValues(ContentValues values) {
        super.writeFieldValues(values);
        values.put(SleepFields.CALENDAR_TIME, calendarTime);
        values.put(SleepFields.CALENDAR, calendar);
        values.put(SleepFields.TIME, time);
        values.put(SleepFields.START_TIME, startTime);
        values.put(SleepFields.END_TIME, endTime);
        values.put(SleepFields.SLEEP_TIME, sleepTime);
        values.put(SleepFields.SLEEP_TYPE, sleepType);
        values.put(SleepFields.IS_SNOOZE, isSnooze ? 1 : 0);
    }

    @SuppressLint("Range")
    @Override
    public void readFieldValues(Cursor c) {
        super.readFieldValues(c);
        calendarTime = c.getString(c.getColumnIndex(SleepFields.CALENDAR_TIME));
        calendar = c.getString(c.getColumnIndex(SleepFields.CALENDAR));
        time = c.getInt(c.getColumnIndex(SleepFields.TIME));
        startTime = c.getInt(c.getColumnIndex(SleepFields.START_TIME));
        endTime = c.getInt(c.getColumnIndex(SleepFields.END_TIME));
        sleepTime = c.getInt(c.getColumnIndex(SleepFields.SLEEP_TIME));
        sleepType = c.getInt(c.getColumnIndex(SleepFields.SLEEP_TYPE));
        isSnooze = c.getInt(c.getColumnIndex(SleepFields.IS_SNOOZE)) == 1;
    }

    @Override
    public void prepareFieldDefs(ArrayList<String> fieldDefs) {
        super.prepareFieldDefs(fieldDefs);
        fieldDefs.add(SleepFields.CALENDAR_TIME + FIELD_TYPE_TEXT);
        fieldDefs.add(SleepFields.CALENDAR + FIELD_TYPE_TEXT);
        fieldDefs.add(SleepFields.TIME + FIELD_TYPE_INTEGER);
        fieldDefs.add(SleepFields.START_TIME + FIELD_TYPE_INTEGER);
        fieldDefs.add(SleepFields.END_TIME + FIELD_TYPE_INTEGER);
        fieldDefs.add(SleepFields.SLEEP_TIME + FIELD_TYPE_INTEGER);
        fieldDefs.add(SleepFields.SLEEP_TYPE + FIELD_TYPE_INTEGER);
        fieldDefs.add(SleepFields.IS_SNOOZE + FIELD_TYPE_INTEGER);
    }

    public static class SleepFields implements Fields {
        public static final String CALENDAR_TIME = "calendar_time";
        public static final String CALENDAR = "calendar";
        public static final String TIME = "time";
        public static final String START_TIME = "start_time";
        public static final String END_TIME = "end_time";
        public static final String SLEEP_TIME = "sleep_time";
        public static final String SLEEP_TYPE = "sleep_type";
        public static final String IS_SNOOZE = "is_snooze";
    }

}
